$(function() {
  $('.mmb_navList h3').on('click',function() {
    $(this).siblings().toggleClass('active')
    $(this).parent().siblings().children().removeClass('active')
  })

  $.ajax({
    url:'http://127.0.0.1:9090/api/getgsshop',
    success: function(info) {
      console.log(info)
      $('.mmb_navList .shop ul').html(template('tmp',info))
    }
  })
  $.ajax({
    url:'http://127.0.0.1:9090/api/getgsshoparea',
    success: function(info) {
      console.log(info)
      $('.mmb_navList .city ul').html(template('tmp2',info))
    }
  })
  
  var shopid = 0
  var areaid = 0
  $('.mmb_navList .shop ul').on('click','li',function() {
    $('.shop .shopTitle').text($(this).text())
    shopid = $(this).data('id')
    $(this).parent().removeClass('active')
    console.log(shopid)
    render()
  })
  $('.mmb_navList .city ul').on('click','li',function() {
    $('.city .cityTitle').text($(this).text())
    areaid = $(this).data('id')
    $(this).parent().removeClass('active')
    console.log(areaid)
    render()
  })
  render()
  function render() {
    $.ajax({
      url : 'http://127.0.0.1:9090/api/getgsproduct',
      data : {
        shopid : shopid || 0,
        areaid : areaid || 0
      },
      success: function(info) {
        console.log(info)
        $('.mmb_items').html(template('tmp3',info))
      }
    })
  }


})